import http from "@/utils/request";
import store from '@/store'
import Cookies from 'js-cookie'
import router from "@/router";

export function userLogout() {
    http.get("/logout").then(result => {
        if (result.data.code == 200) {
            store.commit("SET_ROUTES_STATE", false);
            store.commit("RESET_TABS");
            store.commit("RESET_VUEX", {
                token: "",
                menuList: "",
                currentUser: "",
            });
            store.commit("RESET_ROUTES");
            window.sessionStorage.clear();
            Cookies.remove('sidebarStatus')
            router.replace("/login");
        }
    })

}
export function blobValidate(data) {
  return data.type !== 'application/json'
}
export function treeToArray(tree) {
    const result = [];

    function helper(node, parentId) {
        if (node.id === parentId) return;

        const item = { ...node, children: [] };
        delete item.children;
        result.push(item);

        if (node.children) {
            for (let child of node.children) {
                helper(child, node.id);
            }
        }
    }

    for (let node of tree) {
        helper(node, null);
    }

    return result;
}